﻿/*
 * Created by SharpDevelop.
 * User: 김효순
 * Date: 2012-09-04
 * Time: 오전 10:06
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace 수학함수
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void Bt1Click(object sender, EventArgs e)
		{
			int iPlace = int.Parse(tb2.Text);
			double dVal = double.Parse(tb1.Text);
			
			string output;
			if(iPlace >= 0) {
				int n = (int)Math.Pow(10, iPlace);
				int n1 = (int)(n*dVal+0.5);
				float n2 = (float)(n1/(float)n);
				
				output = String.Format("{0:f}", n2);
			} else {
				double m = Math.Pow(10, (iPlace*-1));
				int m1 = (int)((dVal + m / 2) / m);
				float m2 = (float)(m1*m);
				
				output = string.Format("{0:f}", (int)((dVal + m / 2) / m)*m);
			}
			
			tbResult.Text = output;
		}
		
		void Bt2Click(object sender, EventArgs e)
		{
			Random rd = new Random(Environment.TickCount);
			tbResult.Text = (rd.Next(int.Parse(tb3.Text), int.Parse(tb4.Text))).ToString();
		}
	}
}
